﻿using System;
using System.ComponentModel;
using System.IO;
using System.Windows.Forms;

namespace SceneUnpacker.se.gno
{
    public class MDIParent1 : Form
    {
        private ToolStripMenuItem aboutToolStripMenuItem;
        private ToolStripMenuItem arrangeIconsToolStripMenuItem;
        private ToolStripMenuItem cascadeToolStripMenuItem;
        private int childFormNumber;
        private ToolStripMenuItem closeAllToolStripMenuItem;
        private IContainer components;
        private ToolStripMenuItem contentsToolStripMenuItem;
        private ToolStripMenuItem exitToolStripMenuItem;
        private ToolStripMenuItem fileMenu;
        private ToolStripMenuItem helpMenu;
        private ToolStripButton helpToolStripButton;
        private MenuStrip menuStrip;
        private ToolStripMenuItem newWindowToolStripMenuItem;
        private ToolStripButton openToolStripButton;
        private ToolStripMenuItem openToolStripMenuItem;
        private ToolStripMenuItem statusBarToolStripMenuItem;
        private StatusStrip statusStrip;
        private ToolStripMenuItem tileHorizontalToolStripMenuItem;
        private ToolStripMenuItem tileVerticalToolStripMenuItem;
        private ToolStripMenuItem toolBarToolStripMenuItem;
        private ToolStrip toolStrip;
        private ToolStripSeparator toolStripSeparator1;
        private ToolStripSeparator toolStripSeparator3;
        private ToolStripSeparator toolStripSeparator8;
        private ToolStripStatusLabel toolStripStatusLabel;
        private System.Windows.Forms.ToolTip ToolTip;
        private ToolStripMenuItem viewMenu;
        private ToolStripMenuItem windowsMenu;

        public MDIParent1(string[] args)
        {
            this.InitializeComponent();
            new DragDropSupport(this, new DragDropSupport.DropHandler(this.dragdrop_Drop));
            CommandLine line = new CommandLine(args);
            CommandLine.Option option = new CommandLine.Option("target", true);
            line.AddOption(option);
            string path = line[0];
            if ((path != null) && (path != string.Empty))
            {
                Unpacker childForm = new Unpacker();
                childForm.Archives.Source = new DirectoryInfo(path);
                string str2 = (line[1] != null) ? line[1] : option.Value;
                if (str2 != null)
                {
                    try
                    {
                        childForm.Archives.Destination = new DirectoryInfo(str2);
                    }
                    catch
                    {
                    }
                }
                this.ShowForm(childForm);
            }
        }

        private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            new AboutBox1().ShowDialog();
        }

        private void archiveCollection_EnteringDirectory(object sender, DirectoryInfo d)
        {
            this.toolStripStatusLabel.Text = d.Name;
            Application.DoEvents();
        }

        private void archiveCollection_LeavingDirectory(object sender, DirectoryInfo d)
        {
            this.toolStripStatusLabel.Text = string.Empty;
            Application.DoEvents();
        }

        private void archiveCollection_ProcessEnded(ArchiveCollection sender)
        {
            if (base.InvokeRequired)
            {
                base.Invoke(new ProcessEndedDelegate(this.archiveCollection_ProcessEnded), new object[] { sender });
            }
            else
            {
                this.toolStripStatusLabel.Text = "Finished " + sender.Name;
            }
        }

        private void archiveCollection_ProcessStarted(ArchiveCollection sender)
        {
            if (this.toolStrip.InvokeRequired)
            {
                this.toolStrip.Invoke(new ProcessStartedDelegate(this.archiveCollection_ProcessStarted), new object[] { sender });
            }
            else
            {
                this.toolStripStatusLabel.Text = "Extracting from " + sender.Name;
            }
        }

        private void ArrangeIconsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            base.LayoutMdi(MdiLayout.ArrangeIcons);
        }

        private void CascadeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            base.LayoutMdi(MdiLayout.Cascade);
        }

        private void CloseAllToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (Form form in base.MdiChildren)
            {
                form.Close();
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void dragdrop_Drop(DirectoryInfo dir)
        {
            Unpacker childForm = new Unpacker();
            childForm.Archives.Source = dir;
            this.ShowForm(childForm);
        }

        private void ExitToolsStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            this.menuStrip = new System.Windows.Forms.MenuStrip();
            this.fileMenu = new System.Windows.Forms.ToolStripMenuItem();
            this.openToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator();
            this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.viewMenu = new System.Windows.Forms.ToolStripMenuItem();
            this.toolBarToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.statusBarToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.windowsMenu = new System.Windows.Forms.ToolStripMenuItem();
            this.newWindowToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.cascadeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.tileVerticalToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.tileHorizontalToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.closeAllToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.arrangeIconsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.helpMenu = new System.Windows.Forms.ToolStripMenuItem();
            this.contentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.toolStripSeparator8 = new System.Windows.Forms.ToolStripSeparator();
            this.aboutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.toolStrip = new System.Windows.Forms.ToolStrip();
            this.openToolStripButton = new System.Windows.Forms.ToolStripButton();
            this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
            this.helpToolStripButton = new System.Windows.Forms.ToolStripButton();
            this.statusStrip = new System.Windows.Forms.StatusStrip();
            this.toolStripStatusLabel = new System.Windows.Forms.ToolStripStatusLabel();
            this.ToolTip = new System.Windows.Forms.ToolTip( this.components );
            this.menuStrip.SuspendLayout();
            this.toolStrip.SuspendLayout();
            this.statusStrip.SuspendLayout();
            this.SuspendLayout();
            // 
            // menuStrip
            // 
            this.menuStrip.Items.AddRange( new System.Windows.Forms.ToolStripItem[] {
            this.fileMenu,
            this.viewMenu,
            this.windowsMenu,
            this.helpMenu} );
            this.menuStrip.Location = new System.Drawing.Point( 0, 0 );
            this.menuStrip.MdiWindowListItem = this.windowsMenu;
            this.menuStrip.Name = "menuStrip";
            this.menuStrip.Size = new System.Drawing.Size( 503, 24 );
            this.menuStrip.TabIndex = 0;
            this.menuStrip.Text = "MenuStrip";
            // 
            // fileMenu
            // 
            this.fileMenu.DropDownItems.AddRange( new System.Windows.Forms.ToolStripItem[] {
            this.openToolStripMenuItem,
            this.toolStripSeparator3,
            this.exitToolStripMenuItem} );
            this.fileMenu.ImageTransparentColor = System.Drawing.SystemColors.ActiveBorder;
            this.fileMenu.Name = "fileMenu";
            this.fileMenu.Size = new System.Drawing.Size( 37, 20 );
            this.fileMenu.Text = "&File";
            // 
            // openToolStripMenuItem
            // 
            this.openToolStripMenuItem.ImageTransparentColor = System.Drawing.Color.Black;
            this.openToolStripMenuItem.Name = "openToolStripMenuItem";
            this.openToolStripMenuItem.ShortcutKeys = ( (System.Windows.Forms.Keys)( ( System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.O ) ) );
            this.openToolStripMenuItem.Size = new System.Drawing.Size( 193, 22 );
            this.openToolStripMenuItem.Text = "&Scan Directory";
            this.openToolStripMenuItem.Click += new System.EventHandler( this.OpenSourceFolder );
            // 
            // toolStripSeparator3
            // 
            this.toolStripSeparator3.Name = "toolStripSeparator3";
            this.toolStripSeparator3.Size = new System.Drawing.Size( 190, 6 );
            // 
            // exitToolStripMenuItem
            // 
            this.exitToolStripMenuItem.Name = "exitToolStripMenuItem";
            this.exitToolStripMenuItem.Size = new System.Drawing.Size( 193, 22 );
            this.exitToolStripMenuItem.Text = "E&xit";
            this.exitToolStripMenuItem.Click += new System.EventHandler( this.ExitToolsStripMenuItem_Click );
            // 
            // viewMenu
            // 
            this.viewMenu.DropDownItems.AddRange( new System.Windows.Forms.ToolStripItem[] {
            this.toolBarToolStripMenuItem,
            this.statusBarToolStripMenuItem} );
            this.viewMenu.Name = "viewMenu";
            this.viewMenu.Size = new System.Drawing.Size( 44, 20 );
            this.viewMenu.Text = "&View";
            // 
            // toolBarToolStripMenuItem
            // 
            this.toolBarToolStripMenuItem.Checked = true;
            this.toolBarToolStripMenuItem.CheckOnClick = true;
            this.toolBarToolStripMenuItem.CheckState = System.Windows.Forms.CheckState.Checked;
            this.toolBarToolStripMenuItem.Name = "toolBarToolStripMenuItem";
            this.toolBarToolStripMenuItem.Size = new System.Drawing.Size( 126, 22 );
            this.toolBarToolStripMenuItem.Text = "&Toolbar";
            this.toolBarToolStripMenuItem.Click += new System.EventHandler( this.ToolBarToolStripMenuItem_Click );
            // 
            // statusBarToolStripMenuItem
            // 
            this.statusBarToolStripMenuItem.Checked = true;
            this.statusBarToolStripMenuItem.CheckOnClick = true;
            this.statusBarToolStripMenuItem.CheckState = System.Windows.Forms.CheckState.Checked;
            this.statusBarToolStripMenuItem.Name = "statusBarToolStripMenuItem";
            this.statusBarToolStripMenuItem.Size = new System.Drawing.Size( 126, 22 );
            this.statusBarToolStripMenuItem.Text = "&Status Bar";
            this.statusBarToolStripMenuItem.Click += new System.EventHandler( this.StatusBarToolStripMenuItem_Click );
            // 
            // windowsMenu
            // 
            this.windowsMenu.DropDownItems.AddRange( new System.Windows.Forms.ToolStripItem[] {
            this.newWindowToolStripMenuItem,
            this.cascadeToolStripMenuItem,
            this.tileVerticalToolStripMenuItem,
            this.tileHorizontalToolStripMenuItem,
            this.closeAllToolStripMenuItem,
            this.arrangeIconsToolStripMenuItem} );
            this.windowsMenu.Name = "windowsMenu";
            this.windowsMenu.Size = new System.Drawing.Size( 68, 20 );
            this.windowsMenu.Text = "&Windows";
            // 
            // newWindowToolStripMenuItem
            // 
            this.newWindowToolStripMenuItem.Name = "newWindowToolStripMenuItem";
            this.newWindowToolStripMenuItem.Size = new System.Drawing.Size( 151, 22 );
            this.newWindowToolStripMenuItem.Text = "&New Window";
            this.newWindowToolStripMenuItem.Click += new System.EventHandler( this.ShowNewForm );
            // 
            // cascadeToolStripMenuItem
            // 
            this.cascadeToolStripMenuItem.Name = "cascadeToolStripMenuItem";
            this.cascadeToolStripMenuItem.Size = new System.Drawing.Size( 151, 22 );
            this.cascadeToolStripMenuItem.Text = "&Cascade";
            this.cascadeToolStripMenuItem.Click += new System.EventHandler( this.CascadeToolStripMenuItem_Click );
            // 
            // tileVerticalToolStripMenuItem
            // 
            this.tileVerticalToolStripMenuItem.Name = "tileVerticalToolStripMenuItem";
            this.tileVerticalToolStripMenuItem.Size = new System.Drawing.Size( 151, 22 );
            this.tileVerticalToolStripMenuItem.Text = "Tile &Vertical";
            this.tileVerticalToolStripMenuItem.Click += new System.EventHandler( this.TileVerticalToolStripMenuItem_Click );
            // 
            // tileHorizontalToolStripMenuItem
            // 
            this.tileHorizontalToolStripMenuItem.Name = "tileHorizontalToolStripMenuItem";
            this.tileHorizontalToolStripMenuItem.Size = new System.Drawing.Size( 151, 22 );
            this.tileHorizontalToolStripMenuItem.Text = "Tile &Horizontal";
            this.tileHorizontalToolStripMenuItem.Click += new System.EventHandler( this.TileHorizontalToolStripMenuItem_Click );
            // 
            // closeAllToolStripMenuItem
            // 
            this.closeAllToolStripMenuItem.Name = "closeAllToolStripMenuItem";
            this.closeAllToolStripMenuItem.Size = new System.Drawing.Size( 151, 22 );
            this.closeAllToolStripMenuItem.Text = "C&lose All";
            this.closeAllToolStripMenuItem.Click += new System.EventHandler( this.CloseAllToolStripMenuItem_Click );
            // 
            // arrangeIconsToolStripMenuItem
            // 
            this.arrangeIconsToolStripMenuItem.Name = "arrangeIconsToolStripMenuItem";
            this.arrangeIconsToolStripMenuItem.Size = new System.Drawing.Size( 151, 22 );
            this.arrangeIconsToolStripMenuItem.Text = "&Arrange Icons";
            this.arrangeIconsToolStripMenuItem.Click += new System.EventHandler( this.ArrangeIconsToolStripMenuItem_Click );
            // 
            // helpMenu
            // 
            this.helpMenu.DropDownItems.AddRange( new System.Windows.Forms.ToolStripItem[] {
            this.contentsToolStripMenuItem,
            this.toolStripSeparator8,
            this.aboutToolStripMenuItem} );
            this.helpMenu.Name = "helpMenu";
            this.helpMenu.Size = new System.Drawing.Size( 44, 20 );
            this.helpMenu.Text = "&Help";
            // 
            // contentsToolStripMenuItem
            // 
            this.contentsToolStripMenuItem.Name = "contentsToolStripMenuItem";
            this.contentsToolStripMenuItem.ShortcutKeys = ( (System.Windows.Forms.Keys)( ( System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.F1 ) ) );
            this.contentsToolStripMenuItem.Size = new System.Drawing.Size( 168, 22 );
            this.contentsToolStripMenuItem.Text = "&Contents";
            // 
            // toolStripSeparator8
            // 
            this.toolStripSeparator8.Name = "toolStripSeparator8";
            this.toolStripSeparator8.Size = new System.Drawing.Size( 165, 6 );
            // 
            // aboutToolStripMenuItem
            // 
            this.aboutToolStripMenuItem.Name = "aboutToolStripMenuItem";
            this.aboutToolStripMenuItem.Size = new System.Drawing.Size( 168, 22 );
            this.aboutToolStripMenuItem.Text = "&About ...";
            this.aboutToolStripMenuItem.Click += new System.EventHandler( this.aboutToolStripMenuItem_Click );
            // 
            // toolStrip
            // 
            this.toolStrip.Items.AddRange( new System.Windows.Forms.ToolStripItem[] {
            this.openToolStripButton,
            this.toolStripSeparator1,
            this.helpToolStripButton} );
            this.toolStrip.Location = new System.Drawing.Point( 0, 24 );
            this.toolStrip.Name = "toolStrip";
            this.toolStrip.Size = new System.Drawing.Size( 503, 25 );
            this.toolStrip.TabIndex = 1;
            this.toolStrip.Text = "ToolStrip";
            // 
            // openToolStripButton
            // 
            this.openToolStripButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
            this.openToolStripButton.ImageTransparentColor = System.Drawing.Color.Black;
            this.openToolStripButton.Name = "openToolStripButton";
            this.openToolStripButton.Size = new System.Drawing.Size( 23, 22 );
            this.openToolStripButton.Text = "Open";
            this.openToolStripButton.Click += new System.EventHandler( this.OpenSourceFolder );
            // 
            // toolStripSeparator1
            // 
            this.toolStripSeparator1.Name = "toolStripSeparator1";
            this.toolStripSeparator1.Size = new System.Drawing.Size( 6, 25 );
            // 
            // helpToolStripButton
            // 
            this.helpToolStripButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
            this.helpToolStripButton.ImageTransparentColor = System.Drawing.Color.Black;
            this.helpToolStripButton.Name = "helpToolStripButton";
            this.helpToolStripButton.Size = new System.Drawing.Size( 23, 22 );
            this.helpToolStripButton.Text = "Help";
            // 
            // statusStrip
            // 
            this.statusStrip.Items.AddRange( new System.Windows.Forms.ToolStripItem[] {
            this.toolStripStatusLabel} );
            this.statusStrip.Location = new System.Drawing.Point( 0, 368 );
            this.statusStrip.Name = "statusStrip";
            this.statusStrip.Size = new System.Drawing.Size( 503, 22 );
            this.statusStrip.TabIndex = 2;
            this.statusStrip.Text = "StatusStrip";
            // 
            // toolStripStatusLabel
            // 
            this.toolStripStatusLabel.Name = "toolStripStatusLabel";
            this.toolStripStatusLabel.Size = new System.Drawing.Size( 0, 17 );
            // 
            // MDIParent1
            // 
            this.AllowDrop = true;
            this.ClientSize = new System.Drawing.Size( 503, 390 );
            this.Controls.Add( this.statusStrip );
            this.Controls.Add( this.toolStrip );
            this.Controls.Add( this.menuStrip );
            this.IsMdiContainer = true;
            this.MainMenuStrip = this.menuStrip;
            this.Name = "MDIParent1";
            this.Text = "Scene Unpacker";
            this.DragDrop += new System.Windows.Forms.DragEventHandler( this.MDIParent1_DragDrop );
            this.menuStrip.ResumeLayout( false );
            this.menuStrip.PerformLayout();
            this.toolStrip.ResumeLayout( false );
            this.toolStrip.PerformLayout();
            this.statusStrip.ResumeLayout( false );
            this.statusStrip.PerformLayout();
            this.ResumeLayout( false );
            this.PerformLayout();

        }

        private void MDIParent1_DragDrop(object sender, DragEventArgs e)
        {
        }

        private void OpenSourceFolder(object sender, EventArgs e)
        {
            Unpacker childForm = new Unpacker();
            if (childForm.BrowseSourceFolder())
            {
                this.ShowForm(childForm);
            }
        }

        private void ShowForm(Unpacker childForm)
        {
            this.childFormNumber++;
            childForm.MdiParent = this;
            if (childForm.Text.Equals("Scene Unpacker"))
            {
                childForm.Text = childForm.Text + " " + this.childFormNumber;
            }
            childForm.Archives.EnteringDirectory += new EnteringDirectoryHandler(this.archiveCollection_EnteringDirectory);
            childForm.Archives.LeavingDirectory += new LeavingDirectoryHandler(this.archiveCollection_LeavingDirectory);
            childForm.Archives.ProcessStarted += new ProcessStartedHandler(this.archiveCollection_ProcessStarted);
            childForm.Archives.ProcessEnded += new ProcessEndedHandler(this.archiveCollection_ProcessEnded);
            if (this.childFormNumber == 1)
            {
                childForm.WindowState = FormWindowState.Maximized;
            }
            childForm.Show();
        }

        private void ShowNewForm(object sender, EventArgs e)
        {
            Unpacker childForm = new Unpacker();
            this.ShowForm(childForm);
        }

        private void StatusBarToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.statusStrip.Visible = this.statusBarToolStripMenuItem.Checked;
        }

        private void TileHorizontalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            base.LayoutMdi(MdiLayout.TileHorizontal);
        }

        private void TileVerticalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            base.LayoutMdi(MdiLayout.TileVertical);
        }

        private void ToolBarToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.toolStrip.Visible = this.toolBarToolStripMenuItem.Checked;
        }

        private delegate void ProcessEndedDelegate(ArchiveCollection sender);

        private delegate void ProcessStartedDelegate(ArchiveCollection sender);
    }
}

